﻿#region Using directives
using Microsoft.VisualStudio.TestTools.UnitTesting;

using System.Collections.Generic;

using Weazel.Gezel.Model;
using Weazel.Gezel.Model.Errors;
using Weazel.Math;
#endregion

namespace Weazel.Gezel.Parser.Test.Expressions
{
  [TestClass]
  public class TestParseRangeExpression
  {
    [TestMethod]
    public void TestParseRangeExpression1()
    {
      Tokenizer t = new Tokenizer("a[1]");

      Expression e = ParseExpression.Parse(new Set<Token>(Token.Eof), t);

      // assert no errors
      Assert.AreEqual(0, t.Errors.Count);

      Assert.IsTrue(e is RangeExpression);
      Assert.AreEqual(e.ExpressionType, ExpressionType.Range);

      RangeExpression re = e as RangeExpression;

      Assert.AreEqual<uint>(1, re.To);
      Assert.AreEqual<uint>(1, re.From);
    }

    [TestMethod]
    public void TestParseRangeExpression2()
    {
      Tokenizer t = new Tokenizer("a[1:10]");

      Expression e = ParseExpression.Parse(new Set<Token>(Token.Eof), t);

      // assert no errors
      Assert.AreEqual(0, t.Errors.Count);

      Assert.IsTrue(e is RangeExpression);
      Assert.AreEqual(e.ExpressionType, ExpressionType.Range);

      RangeExpression re = e as RangeExpression;

      Assert.AreEqual<uint>(1, re.To);
      Assert.AreEqual<uint>(10, re.From);
    }
  }
}
